import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
@Slf4j
public class lua_test {
    @Resource
    RedisTemplate redisTemplate;
    @Resource(name = "Lua_test01")
    DefaultRedisScript<Integer> seizeCouponScript;
    @Test
   public void test_seizeCouponScriptLua() {
        String activityId ="7ffd0313-6757-4efb-a861-b1d3b7ef1001";
        // argv: 用户id
        Long userId = 1L;
        int index = (int) (22 % 10);

        //任务库存队列
        String resourceStockRedisKey = String.format("Stock:%s", index);
        //同步队列redisKey
        String couponSeizeSyncRedisKey = String.format("ying:%s", index);
        // 抢券成功列表
        String couponSeizeListRedisKey = String.format("yingying%s%s",activityId, index);

        List<String> list=new ArrayList<>();
        list.add(couponSeizeSyncRedisKey);// 同步队列redisKey
        list.add(resourceStockRedisKey); // 资源库存redisKey
        list.add(couponSeizeListRedisKey); // 抢券成功列表
        Object execute = redisTemplate.execute(seizeCouponScript, list,
                activityId,userId);
    }





}
